/**
 * @date 2006-2-16 14:38:23
 *
 */
package org.nanhill.moo.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.nanhill.moo.domain.permission.Role;

/**
 * User Info.
 * 
 * @author alin [xalinx at gmail dot com]
 * 
 */
public class User {
	/**
	 * User id.
	 */
	private long id;

	/**
	 * Password.
	 */
	private String password;

	/**
	 * User nickname.
	 */
	private String nickname;

	/**
	 * User Fullname.
	 * 
	 */
	private String fullname;

	/**
	 * User intro;
	 */
	private String intro;

		/**
	 * Email address.
	 */
	private String email;

	/**
	 * Privacy flag for showing email to other users.
	 */
	private boolean emailVisible;

	/**
	 * Flag for user status.
	 */
	private int status;

	/**
	 * Creation time.
	 */
	private Date createTime;

	/**
	 * User logo path.
	 */
	private String logoPath;

	/**
	 * User roles.
	 */
	private Role role;

	/**
	 * User groups.
	 * 
	 */
	private Set<UserGroup> groups;

	/**
	 * UserTags.
	 */
	private Set<UserTag> userTags;

	/**
	 * FavorTags.
	 */
	private Set<FavorTag> favorTags;

	public Set<UserGroup> getGroups() {
		return groups;
	}

	void setGroups(Set<UserGroup> groups) {
		this.groups = groups;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFullname() {
		return fullname;
	}

	public void setFullname(String name) {
		this.fullname = name;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public String getLogoPath() {
		return logoPath;
	}

	public void setLogoPath(String logoPath) {
		this.logoPath = logoPath;
	}

	public boolean isEmailVisible() {
		return emailVisible;
	}

	public void setEmailVisible(boolean emailVisible) {
		this.emailVisible = emailVisible;
	}

	public long getId() {
		return id;
	}

	void setId(long id) {
		this.id = id;
	}

	public User() {
	}

	public Set<UserTag> getUserTags() {
		return userTags;
	}

	void setUserTags(Set<UserTag> tags) {
		this.userTags = tags;
	}

	public Set<FavorTag> getFavorTags() {
		return favorTags;
	}

	void setFavorTags(Set<FavorTag> favorTags) {
		this.favorTags = favorTags;
	}

	/**
	 * Join user group.
	 * 
	 * @param group
	 */
	public void joinGroup(UserGroup group) {
		if (null == groups) {
			groups = new HashSet<UserGroup>();
		}
		group.addUser(this);
		groups.add(group);
	}

	/**
	 * Add UserTag to this User.
	 * 
	 * @param userTag
	 */
	public void addUserTag(UserTag userTag) {
		if (null == userTags) {
			userTags = new HashSet<UserTag>();
		}
		userTags.add(userTag);
	}

	public void removeUserTag(UserTag userTag) {
		if (null != userTags) {
			userTags.remove(userTag);
		}
	}

	public void addFavorTag(FavorTag favorTag) {
		if (null == favorTags) {
			favorTags = new HashSet<FavorTag>();
		}
		favorTags.add(favorTag);
	}

	public void removeFavorTag(FavorTag favorTag) {
		if (null != favorTags) {
			favorTags.remove(favorTag);
		}
	}

	/*
	 * User equals if username equals.
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object other) {
		if (null == other)
			return false;
		if (other == this || other instanceof User)
			return true;
		final User user = (User) other;
		return null == email ? null == user.getEmail() : email.equals(user
				.getEmail());
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
}
